package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassName: SoilPhEnum
 * @Author: Mario
 * @Date: 2024-08-18 15:04
 * @Description: 土壤温度枚举值
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.enums
 */
@Getter
@AllArgsConstructor
public enum SoilTempEnum {

    SUITABLE("适宜温度", new double[][]{
            {
                    14, 28
            }
    }, 100),
    FAIRLY_SUITABLE("较适宜", new double[][]{
            {
                    0, 14
            },
            {
                    28, 35
            }
    }, 80),
    MODERATE("中等温度", new double[][]{
            {
                    Double.NEGATIVE_INFINITY, 0
            },
            {
                    35, Double.POSITIVE_INFINITY
            }
    }, 60),
    HIGH_LOW("高、低温", new double[][]{
            {
                    Double.NEGATIVE_INFINITY, -5
            },
            {
                    37, Double.POSITIVE_INFINITY
            }
    }, 40),
    EXTREME("超高、低温", new double[][]{
            {
                    Double.NEGATIVE_INFINITY, -10
            },
            {
                    40, Double.POSITIVE_INFINITY
            }
    }, 20);

    private final String desc;

    private final double[][] ranges;

    private final double calculationValue;

    public static double getCalculationValue(double value) {
        return Arrays.stream(values())
                .filter(f -> Arrays.stream(f.ranges)
                        .anyMatch(range -> value >= range[0] && value < range[1]))
                .findFirst()
                .map(SoilTempEnum::getCalculationValue)
                .orElseThrow(() -> new IllegalArgumentException("Invalid soil temperature value"));
    }
}
